package dao;

import java.sql.SQLException;
import java.util.List;

import entity.Goods;
import entity.Order_item;
import utils.JdbcUtils;

public class Order_itemDao {
	// {1}增加
	public void addOrder_itemDao(Order_item order) throws SQLException {
		String sql = "insert into order_item(oid,gid,g_num,gname,post_sale)values(?,?,?,?,?)";// ?表示占位符，填充插入占位符时表中有几列就写几
		int row = JdbcUtils.update(sql,order.getOid(), order.getGid(),order.getG_num(),order.getGname(),order.getPost_sale());
		System.out.println("已增加" + row + "行数据");
	}

	// {2}删除
	public void deleteOrder_itemDao(Order_item order) throws SQLException {
		String sql = "delete from order_item where oid=?";
		int row = JdbcUtils.update(sql, order.getOid());
		System.out.println("已删除" + row + "行数据");
	}

	// {3}修改
//	public void updateOrder_itemDao(Order_item order) throws SQLException {
//		String sql = "update order_item set order=? where oid=?";
//		int row = JdbcUtils.update(sql, order.getOid(), order.getOid());
//		System.out.println("已修改" + row + "行数据");
//	}

	// {4}根据订单号ID查询
	public Order_item queryByOId(String oid) throws SQLException {
		String sql = "select * from order_item g where g.oid='?' ";
		Order_item goodre = JdbcUtils.query(sql, Order_item.class, oid);
		return goodre;
	}

	// {5}查询所有记录
	public List<Order_item> queryAll() throws SQLException {
		List<Order_item> list = null;
		String sql = "select * from order_item where id<=?";
		list = JdbcUtils.queryList(sql, Order_item.class,20);
		return list;
	}
	// {6}根据订单号查询所有记录
	public List<Order_item> queryOidAll(String oid) throws SQLException {
		List<Order_item> list = null;
		String sql = "select * from order_item where oid = "+ "'" + oid + "'" ;
		list = JdbcUtils.queryList(sql, Order_item.class);
		return list;
	}
	
//	// {5}根据用户ID查询所有记录
//	public static  List<Order_item> queryUidAll(int uid) throws SQLException {
//		List<Order_item> list = null;
//		String sql = "select * from order_item g where g.uid=?";
//		list = JdbcUtils.queryList(sql, Order_item.class,uid);
//		return list;
//	}
}
